<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Meiti extends CI_Controller {
	
	function __construct(){
		parent::__construct();
		if(!isset($_SESSION)){
		    session_start();
		}
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
	}
	
	
	function view($id=''){
		$id = intval($id);
		$vdata = array();
		if ($id>0){
			$this->load->model('Meiti_model');
			$vdata['id'] = $id;
			$vdata['info'] = $this->Meiti_model->get_one($id);
		}
		$this->load->view("/sys_admin/site/meiti_add",$vdata);
	}
	
	function add(){
		$data = array();
		$id = $this->input->post('id');
		$type 		= $this->input->post('type');
		$title 	= $this->input->post('title');
		$url 	= $this->input->post('url');
		
		$config['upload_path'] = 'static/data/upfiles/meiti/';
		$config['allowed_types'] = 'jpg|png';
		$config['file_name'] = uniqid();
		$config['overwrite'] = true;
		$config['max_size'] = '512';
		$config['max_width']  = '2048';
		$config['max_height']  = '3000';
		$this->load->library('upload', $config);
		if(isset($_FILES['image']) && $_FILES['image']['name'] != ''){
			if($this->upload->do_upload('image')){
				$tmp = $this->upload->data();
				$data['image'] = 'static/data/upfiles/meiti/'.$config['file_name'].$tmp['file_ext'];
			}else{
				$this->load->model('log_model');$this->log_model->add_log('[添加][单页链接]['.$title.']');
  				echo "<script>alert('图片上传失败，请重试');window.top.location.href='/sys_admin/meiti/view'</script>";
			}
		}
		
		$data['type'] 	= $type;
  		$data['title'] 	= $title;
  		$data['url'] 	= $url;
  		
  		$this->load->model('meiti_model');
  		if ($id>0){
  			$res = $this->meiti_model->update($data,array('id'=>$id));
  			if ($res){
  				$this->load->model('log_model');$this->log_model->add_log('[修改][单页链接]['.$title.']');
	  			echo "<script>alert('修改成功');window.top.location.href='/sys_admin/meiti/all'</script>";
  			}
  		}else{
  			$data['add_time'] 	= time();
	  		$id = $this->meiti_model->add($data);
	  		if ($id>0){
	  			$this->load->model('log_model');$this->log_model->add_log('[添加][单页链接]['.$title.']');
	  			echo "<script>alert('添加成功');window.top.location.href='/sys_admin/meiti/all'</script>";
	  		}
  		}
  		
  		
	}
	
	function all(){
		$page = $this->input->get('per_page')?$this->input->get('per_page'):0;
		$page_size = 10;
		
		$data['page_size']  = 10;
		$data['page_start'] = intval($page);
		
		$this->load->model('Meiti_model');
		$vdata = $this->Meiti_model->get_list($data);
		
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/meiti/all?pagesize=10';
		$config['total_rows'] = $vdata['count'];
		$config['per_page'] = 10; 
		$this->pagination->initialize($config); 
		
		$this->load->view('/sys_admin/site/meiti_list', $vdata);
	}
	
=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Meiti extends CI_Controller {
    
	function __construct(){
		parent::__construct();
		if(!isset($_SESSION)){
		    session_start();
		}
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
	}
	
	
	function view($id=''){
		$id = intval($id);
		$vdata = array();
		if ($id>0){
			$this->load->model('Meiti_model');
			$vdata['id'] = $id;
			$vdata['info'] = $this->Meiti_model->get_one($id);
		}
		$this->load->view("/sys_admin/site/meiti_add",$vdata);
	}
	
	function add(){
		$data = array();
		$id = $this->input->post('id');
		$type 		= $this->input->post('type');
		$title 	= $this->input->post('title');
		$url 	= $this->input->post('url');
		
		$config['upload_path'] = 'static/data/upfiles/meiti/';
		$config['allowed_types'] = 'jpg|png';
		$config['file_name'] = uniqid();
		$config['overwrite'] = true;
		$config['max_size'] = '512';
		$config['max_width']  = '2048';
		$config['max_height']  = '3000';
		$this->load->library('upload', $config);
		if(isset($_FILES['image']) && $_FILES['image']['name'] != ''){
			if($this->upload->do_upload('image')){
				$tmp = $this->upload->data();
				$data['image'] = 'static/data/upfiles/meiti/'.$config['file_name'].$tmp['file_ext'];
			}else{
				$this->load->model('log_model');$this->log_model->add_log('[添加][单页链接]['.$title.']');
  				echo "<script>alert('图片上传失败，请重试');window.top.location.href='/sys_admin/meiti/view'</script>";
			}
		}
		
		$data['type'] 	= $type;
  		$data['title'] 	= $title;
  		$data['url'] 	= $url;
  		
  		$this->load->model('meiti_model');
  		if ($id>0){
  			$res = $this->meiti_model->update($data,array('id'=>$id));
  			if ($res){
  				$this->load->model('log_model');$this->log_model->add_log('[修改][单页链接]['.$title.']');
	  			echo "<script>alert('修改成功');window.top.location.href='/sys_admin/meiti/all'</script>";
  			}
  		}else{
  			$data['add_time'] 	= time();
	  		$id = $this->meiti_model->add($data);
	  		if ($id>0){
	  			$this->load->model('log_model');$this->log_model->add_log('[添加][单页链接]['.$title.']');
	  			echo "<script>alert('添加成功');window.top.location.href='/sys_admin/meiti/all'</script>";
	  		}
  		}
  		
  		
	}
	
	function all(){
		$page = $this->input->get('per_page')?$this->input->get('per_page'):0;
		$page_size = 10;
		
		$data['page_size']  = 10;
		$data['page_start'] = intval($page);
		
		$this->load->model('Meiti_model');
		$vdata = $this->Meiti_model->get_list($data);
		
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/meiti/all?pagesize=10';
		$config['total_rows'] = $vdata['count'];
		$config['per_page'] = 10; 
		$this->pagination->initialize($config); 
		
		$this->load->view('/sys_admin/site/meiti_list', $vdata);
	}
	
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
}